package easy.删除有序数组中的重复项;

import java.util.Arrays;

/**
 * 删除有序数组中的重复项
 *
 * @author CodeX
 * @since 2021-09-27 17:17:34
 */
public class RemoveDuplicates {

    public static int removeDuplicates(int[] nums) {
        int length = nums.length;
        if (length == 0) {
            return 0;
        }

        int fast = 1, slow = 1;
        while (fast < length) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow++] = nums[fast];
            }
            fast++;
        }

        return slow;
    }

    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 3, 3, 4, 4, 5, 6, 7, 7, 8};
        int i = removeDuplicates(nums);
        System.out.println(i);
        System.out.println(Arrays.toString(nums));
    }

}
